package cn.z2huo.knowledge.concurrency.lock.locksupport;

import cn.hutool.core.thread.ThreadUtil;

import java.util.concurrent.locks.LockSupport;

/**
 * <p>
 *
 * @author z2huo
 */
class LockSupportParkUnparkDemo {

    public static void main(String[] args) {

        Runnable runnable = () -> {
            ThreadUtil.sleep(1000);
            System.out.println("即将进入无限时阻塞");
            LockSupport.park();
            System.out.println("被重新唤醒了");
        };

        Thread thread = new Thread(runnable, "thread-1");
        thread.start();

        LockSupport.unpark(thread);
        System.out.println("unpark 1");
        LockSupport.unpark(thread);
        System.out.println("unpark 2");

        ThreadUtil.sleep(5000);

        LockSupport.unpark(thread);
        System.out.println("unpark 3");
    }

}
